(function (G) {
    G.component({
        options: {
            multipleSlots: true
        },
        props: {
            item:{
                type: Object,
                default:{},
                observer: function (newValue, oldValue) {
                    this.filter(newValue);
                }
            },
            type:{
                type: Number,
                default:1
            },
            tab:{
                type:Object,
                default:{}
            }
        },
        data: function () {
            return {
                distanceShow:'',
                types:{}
            }
        },
        mounted: function () {
            let res = G.Storage.get('modelFacility')
            if(res){
                let types = {}
                for(let i = 0; i < res.type.attr.actions.length; i ++){
                    types[res.type.attr.actions[i].value] = res.type.attr.actions[i].name
                }
                this.setData({
                    types
                })
                this.filter(this.data.item)
            }else{
                G.get('/model/facility',{},{storageName:'modelFacility'}).then(res => {
                    G.Storage.set('modelFacility',res)
                    let types = {}
                    for(let i = 0; i < res.type.attr.actions.length; i ++){
                        types[res.type.attr.actions[i].value] = res.type.attr.actions[i].name
                    }
                    this.setData({
                        types
                    })
                    this.filter(this.data.item)
                })
            }
            
        },
        methods: {
            filter(item){
                if(typeof item.distance == 'number'){
                    this.setData({
                        distanceShow:item.distance > 0 ? (item.distance > 1000 ? ('最近约 ' + parseInt(item.distance / 10) / 100 + ' 千米') : ('最近约 ' + parseInt(item.distance) + ' 米')) : '范围内'
                    })
                }else{
                    this.setData({
                        distanceShow:''
                    })
                }
            }
        }
    })
})(wx.$)